<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>注册</title>
  <style>
    body { font-family: Arial, sans-serif; margin: 20px; }
    label { display: block; margin-top: 10px; }
    input { margin-top: 5px; }
    button { margin-top: 10px; }
  </style>
</head>
<body>
  <h1>注册</h1>
  <div>
    <label for="registerName">用户名：</label>
    <input type="text" id="registerName">
    <label for="registerPassword">密码：</label>
    <input type="password" id="registerPassword">
    <button onclick="register()">注册</button>
  </div>
  <div>
    <a href="login.html">已有账号？登录</a>
  </div>

  <script>
 async function register() {
  const loginName = document.getElementById('registerName').value;
  const password = document.getElementById('registerPassword').value;

  console.log('登录名:', loginName); // 调试信息
  console.log('密码:', password); // 调试信息

  const response = await fetch('http://localhost:3000/api/users/register', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ login_name: loginName, password })
  });

  const result = await response.json();
  if (response.ok) {
    alert('注册成功，请登录');
    window.location.href = 'login.html';
  } else {
    alert(`注册失败: ${result.message}`);
  }
}


  </script>
</body>
</html>
